package com.taptech.doufu.ui.viewholder.personalcenter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.facebook.drawee.view.SimpleDraweeView;
import com.taptech.doufu.R;
import com.taptech.doufu.ui.activity.weex.StartWeexActivityUtils;
import com.taptech.doufu.bean.MineAbstractBean;
import com.taptech.doufu.bean.DFHomeNovelBeans;
import com.taptech.doufu.ui.view.drawcircle.BaseRecyclerViewViewHolder;
import com.taptech.doufu.util.GlideRoundTransform;
import com.taptech.doufu.util.GlideUtil;
import com.taptech.doufu.util.ScreenUtil;

/**
 * Created by longsiyang on 15/10/27.
 */
public class BookListRecyclerViewHolder extends BaseRecyclerViewViewHolder{


    TextView title;
    ImageView ivPic;
    ImageView ivVip;
    TextView tvDesc;
    TextView tvAuthorDesc;
    ImageView ivNum;
    TextView tvStatusInfo;
    View lay;
    RelativeLayout novelMainLayout;


    public BookListRecyclerViewHolder(Context context, View itemView) {
        super(context, itemView);
        mContext = context;
        title = (TextView) itemView.findViewById(R.id.title);
        tvStatusInfo = (TextView) itemView.findViewById(R.id.tvStatusInfo);
        ivPic = (ImageView) itemView.findViewById(R.id.ivPic);
        ivVip = (ImageView) itemView.findViewById(R.id.ivVip);
        tvDesc = (TextView) itemView.findViewById(R.id.tvDesc);
        tvAuthorDesc = (TextView) itemView.findViewById(R.id.tvAuthorDesc);
        lay = itemView.findViewById(R.id.lay);
        ivNum =  itemView.findViewById(R.id.ivNum);
        novelMainLayout = itemView.findViewById(R.id.rl_dfnovel_layout1);
    }



    @Override
    public void setViewHolderChildViewContent(MineAbstractBean tempbean, int position) {

        if (position == 0) {
            novelMainLayout.setPadding(0, ScreenUtil.dip2px(mContext,16),ScreenUtil.dip2px(mContext,12),ScreenUtil.dip2px(mContext,16));
        }else{
            novelMainLayout.setPadding(0, 0,ScreenUtil.dip2px(mContext,12),ScreenUtil.dip2px(mContext,16));
        }
        final DFHomeNovelBeans model = (DFHomeNovelBeans) tempbean;
        if (model != null) {
            title.setText(model.getTitle());
            if (TextUtils.isEmpty(model.getCover_left_top_icon_url())) {
                if ("1".equals(model.getIs_vip())) {
                    ivVip.setVisibility(View.VISIBLE);
                } else {
                    ivVip.setVisibility(View.GONE);
                }
                ivNum.setVisibility(View.GONE);
            } else {
                ivNum.setVisibility(View.VISIBLE);
                ivVip.setVisibility(View.GONE);
                GlideUtil.displayImage(mContext, ivNum, model.getCover_left_top_icon_url());
            }
            if (model.getDesc() != null) {
                tvDesc.setText(model.getDesc());
            }
            if (model.getUser() != null) {
                tvAuthorDesc.setText(model.getUser().getNickname());
            }
            if (model.getStatus_info() != null) {
                tvStatusInfo.setText(model.getStatus_info());
            }
            if (model.getCover() != null) {

                GlideUtil.displayRoundImage(mContext, ivPic, model.getCover(), 3, R.drawable.img_default_loading_l);
            }
            lay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    StartWeexActivityUtils.startBookListInfoActivity(mContext, String.valueOf(model.getId()));
                }
            });
        }

    }
}
